package com.yiwyn.example;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Benchmark)
@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 2, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
public class ParamTest {


    @Param(value = {"1", "10", "100"})
    public Integer param;


    @Benchmark
    public String iterationTest() {

        String a = "";
        for (int i = 0; i < param; i++) {
            a += i;
        }
        return a;
    }


    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder()
                .include(ParamTest.class.getSimpleName())
                .resultFormat(ResultFormatType.JSON)
                .result("./result.json")
                .build();

        new Runner(options).run();
    }

}
